<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>房屋租赁管理系统</title>
    <link rel="stylesheet" type="text/css" href="/static/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/themes/icon.css">
    <script type="text/javascript" src="/static/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="/static/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/common.js?version=0.1"></script>
    <style>
    </style>
</head>
<body>


<div id="list" style="width:97%;height:250px"></div>

<div id="toolbar" class="ToolbarArea">
<%--    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="openAdd()">添加</a>--%>
<%--    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="openEdit()">编辑</a>--%>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del()">删除</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="search()">搜索</a>
</div>

<script type="text/javascript">


    $("#list").datagrid({
        url:'/user/manage/list',
        title: '用户列表',
        fit: true,
        fitColumns: false, // 设置列固定宽度，true值表示自动填满整个横向空间
        toolbar: "#toolbar", // 工具栏id
        idField: 'id',
        frozenColumns: [[{
            field: 'ck',
            checkbox: true
        }]],
        columns: [[
            {field: 'id', title: '编号', width: 180, sortable: false, align: 'left'},
            {field: 'username', title: '用户名', width: 80, sortable: false, align: 'left'},
            {field: 'createTime', title: '注册时间', width: 180, sortable: false, align: 'left'}
        ]],
        onSelect: function (rowIndex, rowData) {
            console.log(rowData);
        }
    });


    function del() {
        var row = $('#list').datagrid('getChecked');

        let ids = new Array();
        $.each(row, function(index, value) {
            ids.push(value.id);
        });

        console.log(ids);

        if (row){
            $.ajax({
                url: "/user/manage/delete",
                type: "POST",
                data: JSON.stringify(ids),
                contentType: "application/json",
                dataType: "json",
                success: function(result) {
                    console.log(result);
                    if (result.success){
                        // $('#dlgSave').dialog('close');
                        $('#list').datagrid('reload');
                    } else {
                        top.$.messager.show({
                            title: 'Error',
                            msg: result.msg
                        });
                    }
                }
            });
        }
    }
</script>
</body>
</html>